package com.yyz.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.yyz.common.BaseContext;
import com.yyz.common.R;
import com.yyz.domain.ShoppingCart;
import com.yyz.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yyz
 * @create 2023-07-26 18:40
 */
@Slf4j
@RestController
@RequestMapping("/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    /**
     * 查询购物车信息
     *
     * @return
     */
    @GetMapping("/list")
    public R list() {
        log.info("查看购物车...");

        List<ShoppingCart> list = shoppingCartService.list();

        return R.success(list);
    }

    /**
     * 添加菜品或套餐到购物车
     * @param shoppingCart
     * @return
     */
    @PostMapping("/add")
    public R<String> add(@RequestBody ShoppingCart shoppingCart) {
        log.info("{}", shoppingCart);

        shoppingCartService.add(shoppingCart);

        return R.success("添加成功！");

    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public R<String> clean(){
        shoppingCartService.clean();

        return R.success("清除成功！");
    }

    @PostMapping("/sub")
    public R sub(@RequestBody ShoppingCart shoppingCart){
        shoppingCartService.sub(shoppingCart);

        return R.success(null);

    }
}
